<template>
  <el-dialog @open="onOpen" title="收货地址" :visible.sync="showVisible">
    <el-form :model="formInfo">
      <el-form-item
        v-if="type == 'upd'"
        label="城市Id"
        :label-width="formLabelWidth">
        <el-input
          v-model="formInfo.cityId"
          autocomplete="off"
          disabled></el-input>
      </el-form-item>
      <el-form-item label="城市名称" :label-width="formLabelWidth">
        <el-input v-model="formInfo.city" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="国家名称" :label-width="formLabelWidth">
        <el-select v-model="formInfo.countryId" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.countryId"
            :label="item.country"
            :value="item.countryId"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="showVisible = false">取 消</el-button>
      <el-button type="primary" @click="onClick">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { doGet } from "@/api";
export default {
  name: "city-dialog",
  computed: {
    showVisible: {
      get: function () {
        return this.dialogFormVisible;
      },
      set: function (newValue) {
        this.$emit("update:visible", newValue);
      },
    },
    formInfo: {
      get: function () {
        return this.formData;
      },
      set: function (v) {
        this.$emit("update:formdata", v);
      },
    },
  },
  props: [
    "updHandler",
    "addHandler",
    "type",
    "formData",
    "dialogFormVisible",
    "formLabelWidth",
  ],
  methods: {
    aaa: function () {},
    onClick() {
      console.log("++++++++++++++++++++");
      console.log(this.addHandler);
      if (this.type == "upd") {
        this.updHandler();
      } else if (this.type == "add") {
        console.log("1111111111111111111");
        this.addHandler.call(null);
      }
    },
    onOpen() {
      if (!this.options) {
        doGet("country").then((res) => {
          this.options = res;
        });
      }
    },
  },
  data() {
    return {
      options: null,
    };
  },
};
</script>

<style scoped></style>
